import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/26 8:26
 * @description 二分查找
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] arr = {0,1,0};
        System.out.println(solution.peakIndexInMountainArray(arr));
    }
    public int peakIndexInMountainArray(int[] arr) {
        int n = arr.length, l = 0, r = n-1;
        int ans = 0;
        while(l <= r) {
            int mid = (l + r) / 2;
            if (arr[mid] > arr[mid+1]) {
                // 二分中经常用变量来保存唯一值
                ans = mid;
                r = mid - 1;
            }else {
                // mid小于右边的数，说明[l, mid + 1]为递增
                l = mid + 1;
            }
        }
        return ans;
    }
}
